/**
 * Created by seeker910 on 2014/9/1.
 * @description 组件名称命名约定：继承container组件，名称以ViewPart结尾;继承control组件，名称以Part结尾
 * 产品列表展示模板
 */
Rsd.define('Rsd.hermit.sections.ProductItemViewPart', {
    extend: 'Rsd.container.Component',
    requires: [
        'Rsd.form.Link'
    ],
    xtype: 'product-item-view', 
     /**
     * @description 标识该组件是否允许编辑
     */
    domEditable:false,
     /**
     * @description true:表示只允许在模板中修改
     */
    editInMaster:false,
    width: '100%',
    style:{ 
         minHeight:400,
         backgroundColor:'#f6f2f23d',
         borderRadius:'8px'
    }, 
    /**
     * 数据源 schema
     */
    schema:{
        type:'object',
        title:'商品信息',
        for:'dataSource',
        properties:{
            'key':{
                type:'string',
                xtype:'product-selector',
                title:'商品SKU',
                default:''
            },
             "spm" :{
                //Site Promotion Management（网站推广管理）
                type:'string',
                xtype: 'promotion-selector',
                title:'推广码',
                default:''
            },
             "showAddCart":{
                type:'boolean',
                xtype:'checkbox',
                title:'显示添加到购物车',
                default:true
            } 
        },
        viewTemplate:{
            'listItemEditView':{
                xtype:'html-box',
                header:false,
                margin: '10px 2% 0 2%',
                width: '95%',
                height: 190,
                labelTagName: 'img',
                label: {
                    position: 'left',
                    content: '{{=dataSource.images[0]}}',
                    height: 'auto',
                    width: 160,
                    style:{
                        maxHeight:'100%'
                    }
                },
                key:"{{=id}}",
                html:'{{=dataSource.title}}({{=dataSource.price}})'
            }
        }
    },
    /**
     * {
     *   key:''
     *   images:[],
     *   price:99, 
     * }
     */
    dataSource: null,
    layout: 'vbox',
    items: [
        {
            xtype: 'image',
            width: '100%',
            flex: 200,
            handler:'btn_go_product_view',
        },
        {
            name: 'title',
            xtype: 'label', 
            label:false,
            width: '100%',
            height: 90, 
            mulitiLine:true,
            text: '',
            style: {
                element:'ctrl',
                lineHeight: 30,
                fontSize: '120%',
                fontWeight: 'bold',
                overflow:'hidden'
            },
             handler:'btn_go_product_view',
        },
        {
            name: 'price',
            xtype: 'label',
            width: '100%',
            height: 60,
            label:{content:'$',space:5,width:30},
            text: '99.90',
            style: {
                fontSize: '120%' 
            },
             handler:'btn_go_product_view',
        },
        {
            header:false,
            height:60,
            width: '100%', 
            layout:{
                type: 'hbox',  
                align:'center', 
            },
            items: [
                {
                    xtype: 'button',
                    label:false,
                    height: 40,
                    width:'auto',
                    text: 'Follow',
                    style:{minWidth:'80px'}
                }, 
                {
                    xtype: 'button',
                    label:false,
                    height: 40,
                    width:'auto',
                    text: 'Add Cart',
                    style:{minWidth:'80px'}
                }
            ]
        }
    ],
   
    /**
     * 
     * @param {*} config 
     */
    constructor: function ProductItemViewPart(config) {
        config = config || {};
        Rsd.apply(this, config);
    },
    /**
     * 
     */
    loadData: function loadData(data) {

        var _data = data || this.dataSource || {};   
        
        //console.log(_data); 
        this.dataSource = _data;
        if (_data.images) {
            this.items[0].setSrc(_data.images[0]);
        }

        this.items[1].setText(_data.title || '');
        this.items[2].setText(_data.price || 'nuset');

        this.callParent();

    },
    btn_go_product_view:function btn_go_product_view()
    {
        Rsd.app.goto('product',"key="+this.dataSource.key);
    }
});